//
//  WmcCombinePhotoGuideView.swift
//  YPWatermarkCamera
//
//  Created by Json on 2023/8/7.
//

import UIKit

class WmcCombinePhotoGuideView: WmcBubbleGuideView {

    override var arrowDirection: WmcButtonBubbleView.ArrowDirection {
        return .down
    }
    /// 控件高度
    let viewHeight: CGFloat
    
    // MARK: Init
    init(width: CGFloat = Wmc_screenWidth, height: CGFloat = Wmc_screenHeight, maskFrame: CGRect) {
        self.viewHeight = height
        super.init(width: width, maskFrame: maskFrame)
    }
    
    public required convenience init() {
        self.init(maskFrame: .zero)
    }

    
    // MARK: UI
    override func makeUI() {
        super.makeUI()
        lineView.image = "icon_point_line_down".wmc_image
        bubbleView.message = "点击完成，可将已拍摄照片合成一张拼图"
        bubbleView.buttonTitle = "我知道了"
        bubbleView.buttonW = 78.0.wmc_autoHor
    }
    
    override func _layoutSubviews() {
        let lineW: CGFloat = 14.0
        let lineH: CGFloat = 54.0
        let bubbleW = 215.0.wmc_autoHor
        let bubbleR = 16.0.wmc_autoHor
        let lineL = maskFrame.minX + (maskFrame.width - lineW) * 0.5
        
        let lineBottom = viewHeight - maskFrame.minY
        lineView.snp.remakeConstraints { make in
            make.bottom.equalTo(-lineBottom)
            make.width.equalTo(lineW)
            make.height.equalTo(lineH)
            make.left.equalTo(lineL)
        }
       
        bubbleView.snp.remakeConstraints { make in
            make.bottom.equalTo(lineView.snp.top).offset(3.0.wmc_autoHor)
            make.width.equalTo(bubbleW)
            make.right.equalTo(-bubbleR)
        }
        // 气泡距离父控件左边间距
        let bubbleL = viewWidth - bubbleR - bubbleW
        // 箭头中心点x坐标的默认位置
        let oldArrowCenterX = bubbleL + bubbleW * 0.5
        // 箭头中心点x坐标的目标位置
        let newArrowCenterX = maskFrame.midX
        // 计算偏移量
        let offsetX = newArrowCenterX - oldArrowCenterX
        // 更新气泡箭头中心x坐标偏移量
        bubbleView.arrowOffsetX = offsetX
    }
    
    
}



